dt={}
while True :
    try:
        word=input()
        dt[word]=dt.get(word,0)+1
    except:
        break
result=[]
for x in dt.items():
    result.append(x)
result.sort(key=lambda x :(-x[1],x[0]))
for x in result:
    print(x[1],x[0])